// const baseUrl = "https://mobile.laiba.shop"
// #ifdef MP-WEIXIN
// const baseUrl = 'http://192.168.3.132:20097' // development
const baseUrl = 'https://mobile.laiba.shop' // production
const globalHeader = {
	header: {'Cookie': uni.getStorageSync('cookie')}
}
// #endif
// #ifdef H5
let baseUrl = ''
if (process.env.NODE_ENV === "development") {
	baseUrl = '/api'
	// baseUrl = ''
} else {
	baseUrl = 'https://mobile.laiba.shop'
}
// const baseUrl = '/api' // development
// const baseUrl = 'https://mobile.laiba.shop' // production
const globalHeader = {
	header: {}
}
// #endif
const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中...',
			mask: true
		})
		uni.request({
			url: baseUrl + options.url,
			method: options.method || 'GET', // 不传默认'GET'请求
			header: globalHeader.header || {},
			data: options.data || {},
			success: (res) => {
				// console.log(res)
				if (res.data.code === 3) {
					uni.showToast({title: '未登入',icon: 'none'})
					let url = encodeURIComponent(window.location.href)
					window.location.href = 'https://mobile.laiba.shop/activity/visitor/auth?url=' + url
					return
				}
				if (res.data.code !== 0) {
					return uni.showToast({
						title: res.data.message || '服务器内部错误',
						icon: 'none'
					})
				}
				resolve(res)
			},
			fail: (err) => {
				uni.showToast({
					title: '网络错误',
					icon: 'none'
				})
				reject(err)
			},
			complete: () => {
				uni.hideLoading()
			}
		})
	})
}

// const showError = (error) => {
	
// }
export {
	myRequest
}